package com.binguo.api.form;

import com.binguo.common.enums.PayType;
import com.binguo.common.exception.ServiceException;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.rmi.ServerException;
import java.util.List;
import java.util.Optional;

import static com.binguo.common.exception.ErrorCode.ORDER_ITEM_NOT_EXISTS;
import static com.binguo.common.exception.ErrorCode.WX_ORDER_NOT_EXIST;

/**
 * Created by haibang on 18/5/9.
 */
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class OrderForm {
    @ApiParam(value = "识别订单号", required = false)
    private String productOrderNo;

    @ApiParam(value = "业务生订单号流水号", required = true)
    @NotNull
    private String serialNumber;

    @ApiParam(value = "商户id", required = true)
    @NotNull
    private Integer shopId;

    @ApiParam(value = "收银台id", required = true)
    @NotNull
    private Integer cashierDeskId;

    @ApiParam(value = "openId", required = true)
    private String openId;

    @ApiParam(value = "顾客id")
    private Integer customerId;

    @ApiParam(value = "顾客姓名")
    private String customerName;

    @ApiParam(value = "顾客手机号")
    private String customerPhone;

    @ApiParam(value = "卡号")
    private String cardNo;

    @ApiParam(value = "实体卡余额(支付后)")
    private Long accountBalance;

    @ApiParam(value = "扫码支付：授权码")
    private String authCode;

    @ApiParam(value = "支付类型 0：二维码支付，1：人脸支付，2：实体卡支付，3：其他支付,  4:商户扫码支付", required = true)
    @NotNull
    private PayType payType;

    @ApiParam(value = "总费用", required = true)
    @NotNull
    private Long totalFee;

    @ApiParam(value = "实际支付费用, 包含附加费", required = true)
    @NotNull
    private Long realFee;

    @ApiParam(value = " 商品总数", required = true)
    @NotNull
    private Integer totalQuantity;

    @ApiParam(value = "是否为市民卡订单", required = true)
    private Integer isSMKOrder;

    @ApiParam(value = "套餐ID", required = true)
    private Integer packageId;

    @ApiParam(value = "瑞景ID", required = true)
    private Integer userId;

    @ApiParam(value = "市民卡Pos加密", required = true)
    private String posseq;

    @ApiParam(value = "市民卡Pos加密后", required = true)
    private String icdata;

    @ApiParam(value = " 商品items", required = true)
    @NotEmpty
    private List<OrderItemForm> items;


    public void validate(List<OrderItemForm> items) {
        // 每页数量超出
        if(items.isEmpty()){
            throw new ServiceException(ORDER_ITEM_NOT_EXISTS);
        }


    }


}
